package org.lee.resbundle;

import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.ResourceBundle;

/**
 * ResourceBundleEx
 * 使用多语言配置文件
 * @author dralee
 * @date 2021-12-28 13:48:21
 **/
public class ResourceBundleEx {
    public static void main(String[] args) {

        Locale[] locales = {Locale.GERMAN, new Locale("sk", "SK"), Locale.ENGLISH, Locale.CHINA, Locale.JAPAN, Locale.KOREA, Locale.FRANCE};

        System.out.println("earth:");
        for(Locale locale : locales){
            getWord(locale, "earth");
        }
        System.out.println("ocean:");
        for(Locale locale : locales){
            getWord(locale, "ocean");
        }
    }

    private static void getWord(Locale locale, String key) {
        ResourceBundle words = ResourceBundle.getBundle("words", locale);
        String value = new String(words.getString(key).getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
        System.out.printf("Locale: %s, Value: %s %n", locale, value);
    }
}
